#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Time       :   20:18
# Author     : Y4
# desc       : 
# File       : 15 字典的过滤.py
from functools import reduce


def guolv(*args):
    for arg in args:
        del dict1[arg]


dict1 = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 60, 'g': 7}
guolv('a', 'b', 'd')
print(dict1)


def guolv2(*args):
    for arg in args:
        dict3[arg] = dict2.pop(arg)


dict2 = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5, 'f': 60, 'g': 7}
dict3 = {}

guolv2('a', 'b', 'd')
print(dict3)


def ymy_filter_json_data(data, arr):
    json_data = None
    for i in arr:
        if json_data is None:
            json_data = data[i]
        else:
            json_data = json_data[i]
    return json_data


data = {
    "hello": "world",
    "students": {
        "zhangsan": {
            "age": 18,
            "addr": "江苏",
            "book": {"title": "西游记", "price": 25}
        }
    }
}

result = ymy_filter_json_data(data, ['students', 'zhangsan'])
print(result)


def ymy_parse(data, *args):
    json_data = reduce(lambda x, y: x[y], args, data)
    return json_data


data = {
    "hello": "world",
    "students": {
        "zhangsan": {
            "age": 18,
            "addr": "江苏",
            "book": {"title": "西游记", "price": 25}
        }
    }
}
result1 = ymy_parse(data, 'students', 'zhangsan', 'book')
print(result1)
